<template>
  <FormItemWrapper :component="component">
    <Rate v-model="formData[component.compConfigData.fieldConfig.bindingFieldName]"
          :count="component.compConfigData.widgetConfig.count"
          :allow-half="component.compConfigData.widgetConfig.allowHalf"
          :disabled="component.compConfigData.widgetConfig.disabled"
          :show-text="component.compConfigData.widgetConfig.showText"
          :clearable="component.compConfigData.widgetConfig.clearable"
          :character="component.compConfigData.widgetConfig.character"
          @on-change="onChangeHandler"
    />
  </FormItemWrapper>
</template>

<script>
import FormLayoutCommonUtil from "@/utils/FormLayoutCommonUtil";
import FormWidgetMixin from "@/mixin/FormWidgetMixin";

export default {
  name: "FormItemRateWidget",
  mixins: [FormWidgetMixin],
  attr: {
    version: '1.0',
    configDataTemp: Object.assign({

      fieldConfig: FormLayoutCommonUtil.buildWidgetFieldConfig(),
      formItemConfig: FormLayoutCommonUtil.buildFormItemConfig({}, '评分'),
      widgetConfig: {
        count: 5,
        allowHalf: false,
        disabled: false,
        showText: false,
        clearable: false,
        character: '',
        icon: '',
        customIcon: ''
      },
      widgetEventCodeConfig: FormLayoutCommonUtil.buildWidgetEventCodeConfig({
        onChange: {remark: '数据改变时触发', resultValues: ['value'], code: ''},
      })

    })
  },
  data() {
    return {}
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.runWidgetOnMountedEventCode()
    },

    onChangeHandler(value) {
      this.runWidgetEventCode('onChange', (fn)=>{
        fn.call(this, value)
      })
    },
  },
  computed: {},
  watch: {}
}
</script>

<style scoped>

</style>
